package com.example.star.mapper;

import com.example.star.entity.Favorite;
import com.example.star.entity.Follow;
import com.example.star.entity.Star;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FollowMapper {
    @Insert("INSERT INTO follows (username,imageResource, name, age, birthDate, birthPlace, nationality, actingExperience, representativeWorks, profession) " +
            "VALUES (#{userName},#{imageResource}, #{name}, #{age}, #{birthDate}, #{birthPlace}, #{nationality}, #{actingExperience}, #{representativeWorks}, #{profession})")
    void insertFollow(Follow follow);

    @Select("SELECT * FROM follows")
    List<Follow> getAllFollows();

    @Select("SELECT * FROM follows WHERE username = #{userName}")
    List<Follow> getFollowByUserName(String userName);

    @Delete("DELETE FROM follows WHERE id = #{id}")
    void deleteFollowById(int id);

    @Select("SELECT * FROM follows WHERE name = #{starName}")
    Follow getFollowByStarName(String starName);

    @Select("SELECT * FROM follows WHERE id = #{id}")
    Follow getFollowById(int id);

    @Select("SELECT * FROM follows LIMIT #{offset}, #{limit}")
    List<Follow> getFollowsByPage(@Param("offset") int offset, @Param("limit") int limit);
    @Select("SELECT COUNT(*) FROM follows")
    int getTotalFollows();

    @Select("SELECT COUNT(*) FROM follows WHERE username = #{userName} AND name = #{starName}")
    int checkFollow(String userName, String starName);

    @Delete("DELETE FROM follows WHERE username = #{userName} AND name = #{starName}")
    int deleteFollow(String userName, String starName);

    // 根据用户名分页获取关注信息
    @Select("SELECT * FROM follows WHERE username = #{userName} LIMIT #{offset}, #{size}")
    List<Follow> getFollowsByUserName(@Param("userName") String userName, @Param("offset") int offset, @Param("size") int size);

    // 根据用户名获取关注信息的总数
    @Select("SELECT COUNT(*) FROM follows WHERE username = #{userName}")
    int getTotalFollowsByUserName(@Param("userName") String userName);

}
